package com.htudata.item.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.htudata.core.util.operation.StringOperationUtils;
import com.htudata.item.dao.ItemDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class ItemKindService {

  @Autowired
  private ItemDao itemDao;
  
  @Value("${item_kind_img_base_url}")
  private String item_kind_img_base_url;
  
  public List<Map<String, Object>> getItemKindListWithoutCache2(boolean forWeb) {
    List<Map<String, Object>> result = new ArrayList<>();
    Map<String, Object> itemKind = null;
    for (Object obj : this.itemDao.selectItemKinds()) {
      itemKind = (Map<String, Object>)obj;
      if ((new StringBuilder()).append(itemKind.get("kindLevel")).append("").toString().equals("1")) {
        itemKind.put("type", itemKind.get("kindId"));
        itemKind.put("img", getItemKindImgTgtUrl((new StringBuilder()).append(itemKind.get("img")).append("").toString()));
        itemKind.put("list", new ArrayList());
        itemKind.put("state", Boolean.valueOf(true));
        itemKind.put("num", Integer.valueOf(0));
        result.add(itemKind);
        continue;
      } 
      if ((new StringBuilder()).append(itemKind.get("kindLevel")).append("").toString().equals("2")) {
        itemKind.put("type", itemKind.get("kindId"));
        itemKind.put("img", getItemKindImgTgtUrl((new StringBuilder()).append(itemKind.get("img")).append("").toString()));
        itemKind.put("list", new ArrayList());
        itemKind.put("state", Boolean.valueOf(true));
        for (Map<String, Object> firstKindTemp : result) {
          if ((new StringBuilder()).append(firstKindTemp.get("kindId")).append("").toString().equals((new StringBuilder()).append(itemKind.get("parentKindId")).append("").toString()))
            ((List<Map<String, Object>>)firstKindTemp.get("list")).add(itemKind); 
        } 
      } 
    } 
    Collections.reverse(result);
    return result;
  }
  
  private String getItemKindImgTgtUrl(String imgName) {
    if (!StringOperationUtils.isValidStr2(imgName))
      return ""; 
    String result = this.item_kind_img_base_url + "/" + imgName;
    return result;
  }
  
  public List<Map<String, Object>> getItemKindListWithoutCache(boolean forWeb) {
    List<Map<String, Object>> result = new ArrayList<>();
    Map<String, Object> firstKind1 = new HashMap<>();
    List<Map<String, Object>> secondKind2List = new ArrayList<>();
    Map<String, Object> secondKind2 = new HashMap<>();
    secondKind2.put("name", "业务数据");
    secondKind2.put("type", Integer.valueOf(11));
    if (forWeb) {
      secondKind2.put("state", Boolean.valueOf(true));
      secondKind2.put("list", new ArrayList());
    } 
    secondKind2List.add(secondKind2);
    secondKind2 = new HashMap<>();
    secondKind2.put("name", "数据源");
    secondKind2.put("type", Integer.valueOf(12));
    if (forWeb) {
      secondKind2.put("state", Boolean.valueOf(true));
      secondKind2.put("list", new ArrayList());
    } 
    secondKind2List.add(secondKind2);
    firstKind1.put("list", secondKind2List);
    firstKind1.put("type", Integer.valueOf(4));
    firstKind1.put("name", "业务指标");
    if (forWeb) {
      firstKind1.put("state", Boolean.valueOf(true));
      firstKind1.put("num", Integer.valueOf(0));
    } 
    result.add(firstKind1);
    firstKind1 = new HashMap<>();
    secondKind2List = new ArrayList<>();
    secondKind2 = new HashMap<>();
    secondKind2.put("name", "数据库");
    secondKind2.put("type", Integer.valueOf(3));
    if (forWeb) {
      secondKind2.put("state", Boolean.valueOf(true));
      secondKind2.put("list", new ArrayList());
    } 
    secondKind2List.add(secondKind2);
    secondKind2 = new HashMap<>();
    secondKind2.put("name", "消息中间件");
    secondKind2.put("type", Integer.valueOf(5));
    if (forWeb) {
      secondKind2.put("state", Boolean.valueOf(true));
      secondKind2.put("list", new ArrayList());
    } 
    secondKind2List.add(secondKind2);
    secondKind2 = new HashMap<>();
    secondKind2.put("name", "中间件");
    secondKind2.put("type", Integer.valueOf(8));
    if (forWeb) {
      secondKind2.put("state", Boolean.valueOf(true));
      secondKind2.put("list", new ArrayList());
    } 
    secondKind2List.add(secondKind2);
    firstKind1.put("list", secondKind2List);
    firstKind1.put("type", Integer.valueOf(3));
    firstKind1.put("name", "软件服务");
    if (forWeb) {
      firstKind1.put("state", Boolean.valueOf(true));
      firstKind1.put("num", Integer.valueOf(0));
    } 
    result.add(firstKind1);
    firstKind1 = new HashMap<>();
    secondKind2List = new ArrayList<>();
    secondKind2 = new HashMap<>();
    secondKind2.put("name", "系统信息");
    secondKind2.put("type", Integer.valueOf(9));
    if (forWeb) {
      secondKind2.put("state", Boolean.valueOf(true));
      secondKind2.put("list", new ArrayList());
    } 
    secondKind2List.add(secondKind2);
    secondKind2 = new HashMap<>();
    secondKind2.put("name", "系统进程");
    secondKind2.put("type", Integer.valueOf(10));
    if (forWeb) {
      secondKind2.put("state", Boolean.valueOf(true));
      secondKind2.put("list", new ArrayList());
    } 
    secondKind2List.add(secondKind2);
    firstKind1.put("list", secondKind2List);
    firstKind1.put("type", Integer.valueOf(2));
    firstKind1.put("name", "系统服务");
    if (forWeb) {
      firstKind1.put("state", Boolean.valueOf(true));
      firstKind1.put("num", Integer.valueOf(0));
    } 
    result.add(firstKind1);
    firstKind1 = new HashMap<>();
    secondKind2List = new ArrayList<>();
    secondKind2 = new HashMap<>();
    secondKind2.put("name", "IT基础设施");
    secondKind2.put("type", Integer.valueOf(1));
    if (forWeb) {
      secondKind2.put("state", Boolean.valueOf(true));
      secondKind2.put("list", new ArrayList());
    } 
    secondKind2List.add(secondKind2);
    secondKind2 = new HashMap<>();
    secondKind2.put("name", "网络连通性");
    secondKind2.put("type", Integer.valueOf(8));
    if (forWeb) {
      secondKind2.put("state", Boolean.valueOf(true));
      secondKind2.put("list", new ArrayList());
    } 
    secondKind2List.add(secondKind2);
    firstKind1.put("list", secondKind2List);
    firstKind1.put("type", Integer.valueOf(1));
    firstKind1.put("name", "基础资源");
    if (forWeb) {
      firstKind1.put("state", Boolean.valueOf(true));
      firstKind1.put("num", Integer.valueOf(0));
    } 
    result.add(firstKind1);
    return result;
  }
}
